// pages/caseReward/myReward/myReward.js
import request from '../../../utils/config.js';
import formatUtil from '../../../utils/util.js';
import cityData from '../../../utils/vendor/cityList.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    current: 0,
    rewardList:[],
    endRewardList:[],
    memUserInfo: {},
  },

  swiperChange: function (e) {
    // console.log(e)
    if (e.detail.source == "touch") {
      this.setData({ current: e.detail.current })
    }
  },
  title1: function () {
    this.setData({
      titleShow: true,
      current: 0,
    })
  },
  title2: function () {
    this.setData({
      titleShow: false,
      current: 1,
    })
  },

  //我的委托详情
  goMyRewardDet: function(e){
    app.globalData.entrustCaseDet = e.currentTarget.dataset.entrustinfo;
    // console.log(app.globalData.entrustCaseDet)
    let applyId = e.currentTarget.dataset.entrustinfo.applyId;
    wx.navigateTo({
      url: '../myRewardDet/myRewardDet?applyId=' + applyId,
    })
  },

  //查询我的委托悬赏列表
  queryMyEntrustList: function () {
    let headerInfo = {
      pageNum: "1",
      pageSize: "",
      sessionId: app.globalData.sessionId,
    }
   
    let bodyInfo = {
      status: "",
      // lawyerUserId: this.data.memUserInfo.userId * 1,
    }
   
    console.log("bodyInfo=", bodyInfo)
    let _this = this;
    wx.showLoading({ title: '加载中', mask: true });
    request.requestLogin_api("queryEntrustConsultApplyList", headerInfo, bodyInfo, (obj) => {
      wx.stopPullDownRefresh();
      console.log("我的悬赏列表=", obj);
      wx.hideLoading(obj);
      if (obj.data.errorCode == '00') {
        let tempData = JSON.parse(obj.data.body);
        let tempList = [],endTempList = [];
        if (tempData.applyVOList.length > 0) {
          tempData.applyVOList.forEach(function (e) {
            e.entrustName = formatUtil.getEntrustNameById(e.entrustType + '');
            // e.endDate = formatUtil.checkYearMonthDay(e.endDate);
            e.operName = e.operName.substring(0, 1) + "律师";
            e.statusName = e.status == 1 ? "待审批" : e.status == 2 ? "审批通过" : e.status == 9?"审批未通过":"";
            if (e.status == 2){
              if (e.ecStatus ){
                e.statusName = e.ecStatus == 2 ? "委托中" : e.ecStatus == 3 ? "已提交" : e.ecStatus == 4?"已付款":"";
                if (e.ecStatus == 4){
                  endTempList.push(e)
                }else{
                  tempList.push(e)
                }
              }else{
                tempList.push(e)
              }
            } else if (e.status == 1){
              tempList.push(e)
            }else if (e.status == 9){
              endTempList.push(e)
            }
            
          });
        }
        _this.setData({
          rewardList: tempList,
          endRewardList: endTempList
        });

      } else {
        wx.showModal({
          title: "查询失败",
          content: obj.data.errorMsg,
          confirmText: '确定',
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
            } else if (res.cancel) {
            }
          }
        })
      }
    }, (obj) => {
      wx.stopPullDownRefresh();
      wx.hideLoading();
      wx.showModal({
        title: "加载失败",
        content: '请尝试下拉界面重新加载',
        confirmText: '确定',
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
          } else if (res.cancel) {
          }
        }
      })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      memUserInfo: app.globalData.persionalInfo
    });
  },

  //成功页面
  goMyRewardSuccess: function(e){
    let entrustinfo = e.currentTarget.dataset.entrustinfo;
    //存储悬赏详情数据
    app.globalData.entrustSuccessData = entrustinfo;
    if (entrustinfo.ecStatus == 4){
      wx.navigateTo({
        url: '../personalInfoSuccess/personalInfoSuccess',
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.queryMyEntrustList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})